// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
console.log("event",event)
  if (event.action && activityHelper[event.action]) {
    const result = await activityHelper[event.action](wxContext, event)
    return result
  }

  return {
    message: 'This action was not found',
    error: -1,
  }
}
//数据库
const db = cloud.database()
const activity = db.collection("solitaire-activity")
const activityHelper = {
  //查询全部活动
  async queryAllActivity(context, params) {
    console.log("queryAllActivity",params)

    return await activity.field({
      _id:false
    }).get()
  },
  //根据类型获取活动
  async queryActivityByType(context, params){
    return await activity.doc(params.type).get()
  }
}